﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Admin/Admin.Master" AutoEventWireup="true"
    CodeBehind="EditArticle.aspx.cs" Inherits="Hengbei.Web.EditArticle"%>

<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server">
    <script type="text/javascript" src="../Scripts/tiny_mce/tinymce.min.js"></script>    
    <script type="text/javascript">
        tinyMCE.init({
            // General options
            language: "zh_CN",
            mode: "specific_textareas",
            editor_selector: "tinymce",
            encoding: "xml",
            theme: "modern",
            menubar: false,

            plugins: "spellchecker,pagebreak,style,layer,table,advhr,advimage,advlink,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,paste,directionality,fullscreen,visualchars,nonbreaking,xhtmlxtras",
            extended_valid_elements: "iframe[src|width|height|name|align]",

            toolbar1: "fontselect fontsizeselect | bold italic underline strikethrough forecolor backcolor | alignleft aligncenter alignright alignjustify | bullist numlist",
            toolbar2: "styleselect formatselect | cut copy paste | searchreplace | undo redo | outdent indent blockquote | link unlink anchor image media | inserttime",
            toolbar3: "table | hr removeformat | subscript superscript | charmap emoticons | print fullscreen | ltr rtl | visualchars visualblocks template pagebreak restoredraft | code preview",
            toolbar_items_size: 'small',

            theme_advanced_toolbar_location: "top",
            theme_advanced_toolbar_align: "left",
            theme_advanced_path_location: "bottom",
            theme_advanced_resizing: true,
            theme_advanced_resize_horizontal: false,
            theme_advanced_styles: "Link to Image: lightbox;Image Right Border: rightbordered;Image Left Border: leftbordered;Darker Text: darker",

             style_formats: [                
                {title: 'Bold text', inline: 'b'},                
                {title: 'Red text', inline: 'span', styles: {color: '#ff0000'}},                
                {title: 'Red header', block: 'h1', styles: {color: '#ff0000'}},                
                {title: 'Example 1', inline: 'span', classes: 'example1'},                
                {title: 'Example 2', inline: 'span', classes: 'example2'},                
                {title: 'Table styles'},                
                {title: 'Table row 1', selector: 'tr', classes: 'tablerow1'}        
            ],        
               
            templates: [                
                {title: 'Test template 1', content: 'Test 1'},                
                {title: 'Test template 2', content: 'Test 2'}        
            ],

            font_formats: "宋体=宋体;仿宋=仿宋;黑体=黑体;楷体=楷体;隶书=隶书;幼圆=幼圆;微软雅黑=微软雅黑;" +
                "Arial=arial,helvetica,sans-serif;Arial Black=arial black,avant garde;Comic Sans MS=comic sans ms,sans-serif;Courier New=courier new,courier;Times New Roman=times new roman,times;Verdana=verdana,geneva",
            // Theme options
//            theme_advanced_buttons1: "bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,|,styleselect,formatselect,fontselect,fontsizeselect,forecolor,backcolor",
//            theme_advanced_buttons2: "cut,copy,paste,pastetext,pasteword,|,search,replace,|,bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,link,unlink,anchor,image,cleanup,help,code,|,insertdate,inserttime,preview",
//            theme_advanced_buttons3: "tablecontrols,|,hr,removeformat,visualaid,|,sub,sup,|,charmap,emotions,iespell,media,advhr",
//            theme_advanced_buttons4: "insertlayer,moveforward,movebackward,absolute,|,styleprops,|,cite,abbr,acronym,del,ins,attribs,|,visualchars,nonbreaking,template,pagebreak,|,ltr,rtl,|,fullscreen",
//            theme_advanced_toolbar_location: "top",
//            theme_advanced_toolbar_align: "left",
//            theme_advanced_statusbar_location: "bottom",
//            theme_advanced_resizing: true,

//            theme_advanced_fonts: "宋体=宋体;仿宋=仿宋;黑体=黑体;楷体=楷体;隶书=隶书;幼圆=幼圆;微软雅黑=微软雅黑;" +
                //"Arial=arial,helvetica,sans-serif;Arial Black=arial black,avant garde;Comic Sans MS=comic sans ms,sans-serif;Courier New=courier new,courier;Times New Roman=times new roman,times;Verdana=verdana,geneva",

            // Example content CSS
//            content_css: "Styles/Article.css",

//            // Drop lists for link/image/media/template dialogs
//            template_external_list_url: "js/template_list.js",
//            external_link_list_url: "js/link_list.js",
//            external_image_list_url: "js/image_list.js",
//            media_external_list_url: "js/media_list.js",

//            // Replace values for the template plugin
//            template_replace_values: {
//                username: "Some User",
//                staffid: "991234"
//            },

            setup: function (editor) {
                editor.on('SaveContent', function (ed) {
                    ed.content = ed.content.replace(/&#39/g, "&apos");
                });
            }
        });
    </script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    <asp:EntityDataSource ID="edsCategories" runat="server" ConnectionString="name=HengbeiEntities"
        DefaultContainerName="HengbeiEntities" EnableFlattening="False" EntitySetName="ArticleCategories">
    </asp:EntityDataSource>
    <asp:EntityDataSource ID="edsArticle" runat="server" ConnectionString="name=HengbeiEntities"
        DefaultContainerName="HengbeiEntities" EnableFlattening="False" EnableInsert="True"
        EnableUpdate="True" EntitySetName="Articles">
    </asp:EntityDataSource>
    <asp:EntityDataSource ID="edsUsers" runat="server" ConnectionString="name=HengbeiEntities"
        DefaultContainerName="HengbeiEntities" EnableFlattening="False" EntitySetName="SiteUsers"
        Select="it.[Name], it.[ID]">
    </asp:EntityDataSource>
    <div style="text-align: center;">
        <h3>
            编辑文章</h3>
    </div>
    <br />
    <div style="width: 100%">
        <asp:DetailsView ID="dvArticle" runat="server" AutoGenerateRows="False" CellPadding="4"
            DataKeyNames="ID" DataSourceID="edsArticle" ForeColor="#333333" GridLines="None"
            Height="600px" Width="100%" DefaultMode="Insert" 
            OnItemInserting="dvArticle_ItemInserting" 
            oniteminserted="dvArticle_ItemInserted">
            <AlternatingRowStyle BackColor="White" ForeColor="#284775" />
            <CommandRowStyle BackColor="#E2DED6" Font-Bold="True" />
            <EditRowStyle BackColor="#999999" />
            <FieldHeaderStyle BackColor="#E9ECF1" Font-Bold="True" />
            <Fields>
                <asp:BoundField DataField="ID" HeaderText="ID" ReadOnly="True" SortExpression="ID"
                    Visible="false" InsertVisible="false" />
                <asp:BoundField DataField="CategoryID" HeaderText="CategoryID" SortExpression="CategoryID"
                    Visible="false" InsertVisible="false" />
                <asp:BoundField DataField="Title" HeaderText="标题" SortExpression="Title" />
                <asp:TemplateField HeaderText="类别" SortExpression="ArticleCategory.Name">
                    <ItemTemplate>
                        <asp:Label ID="lblCategory" runat="server" Text='<%# Eval("ArticleCategory.Name") %>'></asp:Label>
                    </ItemTemplate>
                    <EditItemTemplate>
                        <asp:DropDownList ID="ddlCategories" runat="server" DataSourceID="edsCategories"
                            DataTextField="Description" DataValueField="ID" SelectedValue='<%# Bind("CategoryID") %>'>
                        </asp:DropDownList>
                    </EditItemTemplate>
                </asp:TemplateField>
                <asp:BoundField DataField="UserID" HeaderText="UserID" SortExpression="UserID" Visible="false"
                    InsertVisible="false" />
                <asp:TemplateField HeaderText="用户" SortExpression="SiteUser.Name">
                    <ItemTemplate>
                        <asp:Label ID="lblUser" runat="server" Text='<%# Eval("SiteUser.Name") %>'></asp:Label>
                    </ItemTemplate>
                    <EditItemTemplate>
                        <asp:DropDownList ID="ddlUsers" runat="server" DataSourceID="edsUsers" DataTextField="Name"
                            DataValueField="ID" SelectedValue='<%# Bind("UserID") %>'>
                        </asp:DropDownList>
                    </EditItemTemplate>
                </asp:TemplateField>
                <asp:BoundField DataField="Body" HeaderText="Body" SortExpression="Body" Visible="false"
                    InsertVisible="false" />
                <asp:TemplateField HeaderText="内容" SortExpression="Body">
                    <EditItemTemplate>
                        <asp:TextBox ID="txtContent" class="tinymce" runat="server" Height="500px" TextMode="MultiLine" Width="600px"
                            Text='<%# Bind("Body") %>'></asp:TextBox>
                    </EditItemTemplate>
                </asp:TemplateField>
                <asp:BoundField DataField="CreateDate" HeaderText="CreateDate" SortExpression="CreateDate"
                    Visible="false" InsertVisible="false" />
                <asp:BoundField DataField="LastModifyDate" HeaderText="LastModifyDate" SortExpression="LastModifyDate"
                    Visible="false" InsertVisible="false" />
                <asp:CommandField ShowInsertButton="True" CancelText="取消" UpdateText="保存" InsertText="插入"
                    ShowCancelButton="False" />
            </Fields>
            <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
            <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" Width="100px" />
            <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
            <RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
        </asp:DetailsView>
        <br />
        <br />
        <asp:Panel ID="pnlEditArticle" runat="server">
            <asp:Label ID="LabelStatus" runat="server" Text=""></asp:Label>
            <br />
            <asp:Label ID="lblTitle" runat="server" CssClass="Label" Text="文章标题"></asp:Label>
            <asp:TextBox ID="txtTitle" runat="server" MaxLength="128" Width="200px">
            </asp:TextBox>
            <br />
            <asp:Label ID="lblCategory" runat="server" CssClass="Label" Text="文章类别"></asp:Label>
            <asp:DropDownList ID="ddlCategories" runat="server" DataSourceID="edsCategories"
                DataTextField="Description" DataValueField="ID" Width="205px">
            </asp:DropDownList>
            <br />
            <asp:Label ID="lblContent" runat="server" CssClass="Label" Text="文章内容"></asp:Label>
            <br />
            <asp:TextBox ID="contentTextBox" class="tinymce" runat="server" Height="500px" TextMode="MultiLine"
                Width="600px">
            </asp:TextBox>
            <br />
            <asp:Button ID="cancelButton" runat="server" OnClick="ButtonCancel_Click" Text="取消"
                Width="60px" />
            &nbsp;
            <asp:Button ID="submitButton" runat="server" OnClick="ButtonSubmit_Click" Text="保存"
                Width="60px" />
            <br />            
        </asp:Panel>
    </div>
</asp:Content>
